package com.kongjian.manage.utils;

import java.math.BigDecimal;

public class CalcUtil {


    /**
     * @param aX a的横坐标
     * @param aY a的纵坐标
     * @param bX b的横坐标
     * @param bY b的纵坐标
     * @param cX c的横坐标
     * @return c的横坐标
     */
    public static double formula(double aX, double aY, double bX, double bY, double cX) {
        double lon = aX - bX;
        double lat = aY - bY;
        double b = lat / lon;
        //y=bx+k;
        double k = aY - b * aX;
        System.out.println(lon);
        System.out.println(lat);
        return (b * cX + k);
    }

    /**
     * @param aX a的横坐标
     * @param aY a的纵坐标
     * @param bX b的横坐标
     * @param bY b的纵坐标
     * @param cX c的横坐标
     * @return c的横坐标
     */
    public static BigDecimal formula(BigDecimal aX, BigDecimal aY, BigDecimal bX, BigDecimal bY, BigDecimal cX) {
        BigDecimal lon = aX.subtract(bX);
        BigDecimal lat = aY.subtract(bY);
        BigDecimal b = lat.divide(lon);

        //y=bx+k;
        BigDecimal k = aY.subtract(b.multiply(aX));
        return (b.multiply(cX).add(k));
    }


    public static void main(String[] args) {
        double aX = 280.930;
        double aY = 0.200;
        double bX = 280.920;
        double bY = 0.100;

        double cX = 280.925;

        double v = formula(aX, aY, bX, bY, cX);
        System.out.println(v);
    }


}
